package cn.ac.iie.kgmanager.domain;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;

/**
 * @ClassName Relation
 * @Author tjh
 * @Date 19/6/12 上午10:12
 * @Version 1.0
 **/
@Data
public class Relation {
    private String id = UUID.randomUUID().toString().replace("-", "");
    private String startId;
    private String endId;
    private String name;
    private Map<String, Object> properties;

    public void addProperty(String key, Object value) {
        if (this.properties == null) {
            this.properties = new HashMap<>();
        }

        this.properties.put(key, value);
    }

    public void addProperties(Map<String, Object> properties) {
        if (this.properties == null) {
            this.properties = new HashMap<>();
        }

        this.properties.putAll(properties);
    }

    public void setProperties(Map<String, Object> properties) {
        this.properties = properties;
        addProperty("id", this.id);
        addProperty("startId", this.startId);
        addProperty("endId", this.endId);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        if (!super.equals(o)) return false;
        Relation relation = (Relation) o;
        return Objects.equals(startId, relation.startId) &&
                Objects.equals(endId, relation.endId) &&
                Objects.equals(name, relation.name);
    }

    @Override
    public int hashCode() {

        return Objects.hash(super.hashCode(), startId, endId, name);
    }
}
